{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
    <table class="layui-hide" id="kind" lay-filter="kind"></table>
</div>
<script type="text/html" id="toolbarKind">
    <div class="layui-btn-container">
        <span class="layui-btn layui-btn-normal layui-btn-sm add-config">+ 添加类型</span>
    </div>
</script>
<script type="text/html" id="barKind">
    <div class="layui-btn-group">
        <span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>
        <span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>
    </div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];

    function gouguInit() {
        let table = layui.table, tool = layui.tool, form = layui.form;

        layui.pageTable = table.render({
            elem: '#kind',
            title: '表类型',
            toolbar: '#toolbarKind',
            url: '/admin/data/config', //数据接口
            page: true, //开启分页
            limit: 10,
            cols: [
                [{
                    field: 'id',
                    hide: true
                }, {
                    field: 'type',
                    title: '字段类型',
                    align: "center",
                    width: 120,
                    sort: true
                }, {
                    field: 'name',
                    title: '名称',
                    align: 'center',
                    width: 120
                }, {
                    field: 'value',
                    hide: true
                }, {
                    field: 'right',
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#barKind',
                    width: 132,
                    align: 'center'
                }]
            ]
        });

        //表头工具栏事件
        $('body').on('click', '.add-config', function () {
            tool.side("/admin/data/add_config");
        });

        //监听行工具事件
        table.on('tool(kind)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') {
                tool.side('/admin/data/add_config?id=' + data.id);
            } else if (obj.event === 'del') {
                layer.confirm('您确定要删除吗', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    };
                    tool.delete("/admin/data/del_config", {id: data.id}, callback);
                    layer.close(index);
                });
            }
        });
    }
</script>
{/block}
<!-- /脚本 -->